//
//  UIBarButtonItem+convence.swift
//  SYWeibo
//
//  Created by Saya on 16/4/8.
//  Copyright © 2016年 黄金果. All rights reserved.
//

import UIKit

//指定的构造函数 和 属性都不能在 扩展中使用

//在实际开放中,多将自定义的属性写在分类中
extension UIBarButtonItem {
    //够一个构造函数
    convenience init(imgName:String? ,title:String? = nil,target: AnyObject?, action: Selector) {
        self.init()
        let btn = UIButton()
        if let tempName = imgName{
            btn.setImage(UIImage(named: tempName), forState: .Normal)
            btn.setImage(UIImage(named: tempName+"_highlighted"), forState: .Highlighted)
        }
        
        btn.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        
        btn.setTitle(title, forState: .Normal)
        btn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        btn.setTitleColor(UIColor.orangeColor(), forState: .Highlighted)
        btn.titleLabel?.font = UIFont.systemFontOfSize(14)
        
        btn.sizeToFit()
        //设置按键的间距
        btn.imageEdgeInsets = UIEdgeInsets(top: 0, left: -10, bottom: 0, right: 10)
        customView = btn
    }
}
